// UDPDevice.h
// created by anve 2019.11.6

#ifndef UDP_DEVICE_H_
#define UDP_DEVICE_H_

#include "UDPServer.h"
#include "define.h"

#if 0
typedef struct _CrossDeviceList {
	char *name;
	struct _CrossDeviceList *next;
} CrossDeviceList;
#endif

class UDPDevice {
public:
	/**************************************************************
	 * Default constructor: create an instance of our serial interface
	 *   object.
	 * Parameters: None, though it could be convenient to have default
	 *   settings specified here as well as possibly a default port name.
	 * Returns: Nothing(it is a constructor)
	 */
	UDPDevice();
	/*
	 * Default deconstructor: delete an instance of out serial interface
	 */
	~UDPDevice();
	
	
	static CrossDeviceList* getDeviceList(void);
	/*
	 * open: opens the udp.
	 * Parameters:
	 *   deviceName: an array of chars containing a NULL terminated string
	 *   example:  UDP:192.168.0.100:1000,HOST:192.128.0.205:3333
	 * Returns: a boolean indicating success or failure
	 */
	bool open(char* deviceName);
	/*
	 * close: closes the serial port
	 * Parameters: None.
	 * Returns: a boolean indicating success or failure
	 */
	bool close();
	
	void setSpeed(int speed);
	/*
	 * readBuf: read in a buffer of words
	 * Parameters:
	 *   buf: The buffer to read words into
	 *   bufSize: the number of words to read. This should be less than
	 *     or equal to the size of buf
	 * Returns: the number of words actually read
	 */
	int readBuf(char * buf, int bufSize);
	/*
	 * writeBuf: write out a buffer of words
	 * Parameters:
	 *   buf: The buffer to write words from
	 *   bufSize: the number of words to write. This should be less than
	 *     or equal to the size of buf
	 * Returns: the number of words actually written
	 */
	int writeBuf(char * buf, int bufSize);
	
	sockaddr_in * getRemoteAddr(void);

private:
	
	char*destIP;
	unsigned short destPort;
	UDPServer *server;
	sockaddr_in * remoteAddr;

};



















#endif
